package com.sap.mall.order.listener;

import com.rabbitmq.client.Channel;
import com.sap.common.to.mq.SeckillOrderTo;
import com.sap.mall.order.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@RabbitListener(queues = "order.seckill.order.queue")
@Component
public class OrderSeckillListener {

    @Autowired
    OrderService orderService;

    @RabbitHandler
    public void listener(SeckillOrderTo seckillOrder, Channel channel, Message message) {
        log.info("===》准备创建秒杀单{}",seckillOrder.getOrderSn());
        orderService.createSeckillOrder(seckillOrder);
        log.info("===》完成创建秒杀单{}===》",seckillOrder.getOrderSn());
    }
}
